package erwiki.ui.app.dialogs;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.layout.GridData;

/**
 * Диалог использовался для PagesSearchHandler, в E3-версии ElWiki.
 *
 * @author vfedorov
 */
public class SearchingDialog extends Dialog {
	private static final long serialVersionUID = -2961792250719639413L;

	private String searchRequest;
	private Text txtRequest;

	// == CODE ================================================================

	/**
	 * Create the dialog.
	 * 
	 * @param parentShell
	 */
	public SearchingDialog(Shell parentShell) {
		super(parentShell);
	}

	@Override
	protected void configureShell(Shell newShell) {
		super.configureShell(newShell);
		newShell.setText("Поиск");
	}

	/**
	 * Create contents of the dialog.
	 * 
	 * @param parent
	 */
	@Override
	protected Control createDialogArea(Composite parent) {
		Composite container = (Composite) super.createDialogArea(parent);
		container.setLayout(new GridLayout(2, false));

		Label lblNewLabel = new Label(container, SWT.NONE);
		lblNewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		lblNewLabel.setText("Request:");

		this.txtRequest = new Text(container, SWT.BORDER);
		this.txtRequest.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

		this.txtRequest.setText("wikiwiki"); // :FVK: WORKAROUND.
		
		return container;
	}

	/**
	 * Create contents of the button bar.
	 * 
	 * @param parent
	 */
	@Override
	protected void createButtonsForButtonBar(Composite parent) {
		// :FVK: createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
		// :FVK: createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
		createButton(parent, IDialogConstants.OK_ID, "Ввод", true);
		createButton(parent, IDialogConstants.CANCEL_ID, "Отмена", false);
	}

	/**
	 * Return the initial size of the dialog.
	 */
	@Override
	protected Point getInitialSize() {
		return new Point(450, 300);
	}

	@Override
	protected void cancelPressed() {
		// TODO Auto-generated method stub
		super.cancelPressed();
	}

	@Override
	protected void okPressed() {
		this.searchRequest = this.txtRequest.getText();

		super.okPressed();
	}

	public String getSearchRequest() {
		return this.searchRequest;
	}
}
